﻿using Aker.DevTeam;
using Extensions;
using System;
using System.Data;
using System.Windows.Forms;

namespace Aker.Cikislar
{
    public partial class DahiliSevkKabul : XForm
    {
        public DahiliSevkKabul()
        {
            InitializeComponent();
        }

        private void DahiliSevkKabul_Load(object sender, EventArgs e)
        {
            DataSet ds = Data.DM.ExecuteDataSet("GetDahiliSevk2", AppSession.UserInfo.UserId);

            //DataSet ds = Data.DM.ExecuteDataSet("GetDahiliSevk2", 24);

            //DataTable dtDetail = ds.Tables[1];
            //ds.Relations.Add("FK", ds.Tables[0].Columns["CikisId"], ds.Tables[1].Columns["CikisId"]);

            BindingSource bs = new BindingSource(ds, ds.Tables[0].TableName);
            //BindingSource bsDetail = new BindingSource(bs, "FK");

            gvMaster.Init(bs);
            //gvDetail.Init(bsDetail);

            gvMaster.MakeReadOnly();
            //gvDetail.MakeReadOnly();

            splitContainerControl1.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;

            GridMenu gm = GridManager.GetManager(gvMaster).GridMenu;
            gm.AddMenu("Sevkiyatı Kabul Et", Kabul);

            gvMaster.BestFitColumns();
        }

        private void Kabul(object sender, EventArgs e)
        {
            int[] rows = gvMaster.GetSelectedRows();
            System.Collections.Generic.List<int> ids = new System.Collections.Generic.List<int>();
            foreach (int i in rows)
                ids.Add(gvMaster.GetDataRow(i)["StokLinesId"].ToIntNN());

            if (ids.Count > 0)
            {
                Data.DM.ExecuteNonQuery("DahiliSevkKabul", string.Join(",", ids));
                DataSet ds = Data.DM.ExecuteDataSet("GetDahiliSevk2", AppSession.UserInfo.UserId);
                gvMaster.VeriyiGuncelle(ds.Tables[0]);
                ShowInfo("Sevkiyat depoya alınarak kabul edildi.");
            }
            else
                ShowError("Kabul etmek istediğiniz satıları seçin!");
        }

        private void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }
    }
}
